package com.jt.www.domain.bo;

import com.alibaba.fastjson.JSON;
import com.jt.www.domain.enums.common.BusinessTypeCodeEnum;
import com.jt.www.domain.po.OfflineEndorse;
import com.jt.www.domain.vo.FileVO;
import com.jt.www.domain.vo.OfflineEndorsePolicyVo;
import com.jt.www.util.MyStringUtils;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 线下批单
 * Created by shaoyn on 2020/05/25.
 */
public class OfflineEndorseBO {

    public static final Logger log = LoggerFactory.getLogger(OfflineEndorseBO.class);

    @ApiModelProperty(value = "关联保单-已修改成查询的线上的保单")
    private OfflineEndorsePolicyVo offlineEndorsePolicyVo;

    @ApiModelProperty(value = "线下录入批单")
    private OfflineEndorse offlineEndorse;

    @ApiModelProperty(value = "附件文件")
    private List<FileVO> attachedFiles;

    @ApiModelProperty(value = "佐证文件")
    private List<FileVO> evidenceFiles;

    public OfflineEndorseBO(OfflineEndorsePolicyVo offlineEndorsePolicyVo, OfflineEndorse offlineEndorse) {
        this.offlineEndorsePolicyVo = offlineEndorsePolicyVo;
        this.offlineEndorse = offlineEndorse;
    }

    public List<FileVO> getAttachedFiles() {
        if (null == offlineEndorse || StringUtils.isBlank(offlineEndorse.getAttachedFile())) {
            return attachedFiles;
        }
        try {
            List<FileVO> fileVOS = JSON.parseArray(offlineEndorse.getAttachedFile(), FileVO.class);
            for (FileVO fileVO : fileVOS) {
                fileVO.setFileUrl(MyStringUtils.createFileUrl("edu-svc", BusinessTypeCodeEnum.F003.getCode(), String.valueOf(offlineEndorse.getId()), "0", fileVO.getFileId()));
            }
            return fileVOS;
        } catch (Exception e) {
            log.error("批单号为{}的线下投批单，附件Json格式不正确!", offlineEndorse.getEndorseNo());
        }
        return attachedFiles;
    }

    public List<FileVO> getEvidenceFiles() {
        if (null == offlineEndorse || StringUtils.isBlank(offlineEndorse.getEvidenceFile())) {
            return evidenceFiles;
        }
        try {
            List<FileVO> fileVOS = JSON.parseArray(offlineEndorse.getEvidenceFile(), FileVO.class);
            for (FileVO fileVO : fileVOS) {
                fileVO.setFileUrl(MyStringUtils.createFileUrl("edu-svc", BusinessTypeCodeEnum.F005.getCode(), String.valueOf(offlineEndorse.getId()), "0", fileVO.getFileId()));
            }
            return fileVOS;
        } catch (Exception e) {
            log.error("批单号为{}的线下投批单，佐证文件Json格式不正确!", offlineEndorse.getEndorseNo());
        }
        return evidenceFiles;
    }

    public void setEvidenceFiles(List<FileVO> evidenceFiles) {
        this.evidenceFiles = evidenceFiles;
    }

    public void setAttachedFiles(List<FileVO> attachedFiles) {
        this.attachedFiles = attachedFiles;
    }

    public OfflineEndorsePolicyVo getOfflineEndorsePolicyVo() {
        return offlineEndorsePolicyVo;
    }

    public void setOfflineEndorsePolicyVo(OfflineEndorsePolicyVo offlineEndorsePolicyVo) {
        this.offlineEndorsePolicyVo = offlineEndorsePolicyVo;
    }

    public OfflineEndorse getOfflineEndorse() {
        return offlineEndorse;
    }

    public void setOfflineEndorse(OfflineEndorse offlineEndorse) {
        this.offlineEndorse = offlineEndorse;
    }
}
